package com.xwh.gatewey.client;

import com.xwh.gatewey.properties.Result;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;


@Service
public class SystemService {


    private final WebClient webClient;

    public SystemService(WebClient.Builder webClientBuilder) {
        this.webClient = webClientBuilder.baseUrl("lb://cms-system").build();
    }

    public Mono<Result> checkToken(String authToken) {
        return webClient.post()
                .uri(uriBuilder -> uriBuilder
                        .path("/auth/checkToken")
                        .queryParam("authToken", authToken)
                        .build()).retrieve()
                .bodyToMono(Result.class)
                .doOnError(Throwable::printStackTrace);
    }

    public Mono<Result> checkAuthorize(String userInfoStr, String type, String path) {
        // Assuming that these parameters are sent as query parameters
        return webClient.post()
                .uri(uriBuilder -> uriBuilder
                        .path("/auth/checkAuthorize")
                        .queryParam("userInfoStr", userInfoStr)
                        .queryParam("type", type)
                        .queryParam("path", path)
                        .build())
                .retrieve()
                .bodyToMono(Result.class)
                .doOnError(Throwable::printStackTrace);
    }
}
